package com.thiswhyme.hystrix.server2.feign;

import com.google.common.reflect.TypeToken;
import com.thiswhyme.common.response.ResponseVo;
import com.thiswhyme.hystrix.server2.dto.UserDto;
import org.springframework.stereotype.Service;

import java.lang.reflect.Type;
import java.util.List;

/**
 * Created by thiswhyme on 2020/9/3.
 */
@Service
public class UserFeignFallbackService implements UserFeignService {

    @Override
    public ResponseVo<List<UserDto>> listUsers() {
        return defaultFallBack(new TypeToken<UserDto>(){}.getType());
    }

    @Override
    public ResponseVo<String> queryUserName(Integer userId) {
        return defaultFallBack(new TypeToken<String>(){}.getType());
    }

    private <T> ResponseVo<T> defaultFallBack(Type type) {
        return ResponseVo.failure("403", "feign fallback");
    }
}
